const app = new getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    prompt: '',
    default_img: {},
    is_login: 0,
    order_info:{},
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let order_id = app.checkEmpty(options.scene, 0);

    this.setData({
      order_id: order_id
    })

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    let is_login = that.data.is_login;

    if (is_login == 0) {
      let second = 0;
      let timer = setInterval(function () {

        second++;
        let token = app.globalData.token;
        if (token != '') {
          app.defaultImg(that, true);
          clearInterval(timer);
        }

        if (second >= 30) {
          app.showBox('登录超时', 2000);
          setTimeout(function () {
            wx.switchTab({
              url: '/pages/index/index',
            })
          }, 2000)
        }
      }, 1000);
    } else {
      app.defaultImg(that, true);
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  loadInfo: function () {
    let that = this;
    let order_id = that.data.order_id;
    app.sendRequest({
      url: 'System.Order.getPickupOrderInfo',
      data: {
        order_id: order_id
      },
      success: function (res) {
        console.log(res);
        if (res.code == 0) {
          let order_info = res.data;
          let goods_list = app.checkEmpty(order_info.order_goods,[]);
          for (let index in goods_list){
            goods_list[index].picture_info.pic_cover_micro = app.IMG(goods_list[index].picture_info.pic_cover_micro);
          }
          order_info.order_goods = goods_list;

          that.setData({
            order_info: order_info
          })
        }
      }
    })
  },

  confirmPickUp:function(e){
    let that = this;
    let order_id = e.currentTarget.dataset.order_id;

    app.sendRequest({
      url:'System.Order.confirmPickup',
      data:{
        order_id: order_id,
        buyer_name: that.data.order_info.receiver_name,
        buyer_phone: that.data.order_info.receiver_mobile
      },

      success:function(res){
        if(res.code > 0){
          app.showBox(that, res.message);
          setTimeout(function(){
            wx.switchTab({
              url: '/pages/member/member/member',
            })
          },1500);
        }else{
          app.showBox(that, res.message);
        }
      }
      
    })

  }
})